home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4863 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: warrane.connect.com.au!ieaust1!Damien_Gardner
  2. From: Damien_Gardner@ieaust.org.au (Damien Gardner)
  3. Reply-To: Damien_Gardner@ieaust.org.au
  4. Newsgroups: comp.lang.c
  5. Distribution: world
  6. Subject: Interrupt-driven Serial I/O
  7. Date: 08 Feb 1996 04:31:40 GMT
  8. Message-ID: <2575630302.506400733@ieaust.org.au>
  9. Organization: Institution  of Engineers, Australia
  10.  
  11. Hi there!  I'm in the midst of trying to write a Serial I/O library
  12. (Interrupt driven).  The Transmit routine (which is hooked into int 0x1c,
  13. the 55ms timer tick interrupt), works fine.  However, I cannot get the
  14. receive routine (which is hooked into the appropriate Int for the Com port)
  15. to work (it seems that it is not even being called!). 
  16. I've got it incrementing a global variable (inttemp), each time it is
  17. called, and it is not incrementing.  Could someone who has managed to
  18. get this sort of thing to work, give me a few tips?  
  19. (Sorry about the messy code, but I've spent the entire day, 
  20. adding, deleting, and changing bits.
  21.  
  22. Begin file fragment
  23. >>>>>>
  24. void setintr(void)
  25. {
  26.  
  27.     //print Status information here (removed)
  28.  
  29.     /* save the old interrupt vector */
  30.     oldhandler = getvect(INTR);
  31.     oldhandler2 = getvect(0x1C);
  32.  
  33.     /* install the new interrupt handler */
  34.     setvect(INTR, rcv_handler);     // install the receive handler.
  35.     setvect(0x1C, trx_handler);    // install the transmit handler.
  36.     // enable IRQ (INTR - 0x08)
  37.     outportb(0x21, inportb(0x21) & (0xFF - (1 << (INTR - 0x08))));
  38.     outportb(PortAddr + 4, 11); // Enable RTS, DTR, and OUT2
  39.     outportb(PortAddr + 1, 1); // enable the RC Interrupt
  40. }
  41.  
  42. void remintr(void)
  43. {
  44.     outportb(0x21, inportb(0x21) | (1 << (INTR - 0x08)));
  45.     outportb(PortAddr + 1, 0); // disable all Interrupts from the Com port.
  46.     /* reset the old interrupt handler */
  47.     setvect(INTR, oldhandler);
  48.     setvect(0x1C, oldhandler2);
  49. }
  50. void interrupt rcv_handler(void)
  51. {
  52.     char tmp;
  53.     inttemp++;
  54.     disable();
  55.     while (!((tmp = inp(PortAddr + 2)) & 1) && (tmp & 4))
  56.     {
  57.         tmp = inportb(PortAddr);
  58.         if (!RC_full()) RC_put(tmp);
  59.     }
  60.     enable();
  61. }
  62. <<<<<<<
  63. End file fragment
  64.  
  65. Notes:
  66.  
  67. char INTR   is an 8-bit value, defined globally, and set by another routine -
  68.  
  69.         it contains the Int number to install the rcv_handler on.
  70.         (= com IRQ + 0x08)
  71.  
  72. unsigned int PortAddr  is a 16-bit value, defined globally, and set by 
  73.         another routine - it contains the base Address of the required
  74.         serial port.
  75.  
  76. I set OUT2 (in the Modem Control Register) high, as I beleive that this is
  77. required, to enable interrupts out of the 8250/16550.  - I got this from a
  78. Pascal modem library, called 'comm_tp5'.   If anyone knows where I can get
  79. the 'c' version of this, I *really* appreciate it! - That'll mean that 
  80. I won't have to continue with this bloody thing!
  81.  
  82. Cheers,
  83.  
  84. Damien Gardner Jnr
  85. Moderator, Frequent Questions,
  86. Engineering OnLine, Australia.
  87. February 7, 1996
  88.